//
//  UIBarButtonItem+Button.swift
//  张伟的微博
//
//  Created by 伟 on 16/3/2.
//  Copyright © 2016年 伟. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    class func creatBarButtonItem(imageNamed:String) -> UIBarButtonItem{
        
        let barButton = UIButton()
        barButton.setBackgroundImage(UIImage(named: imageNamed), forState: UIControlState.Normal)
        barButton.setBackgroundImage(UIImage(named: imageNamed + "_highlighted"), forState: UIControlState.Highlighted)
        barButton.sizeToFit()
        return UIBarButtonItem(customView: barButton)
        
    }
    
    
    //便利构造函数
    convenience init(imageNamed:String) {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: imageNamed), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: imageNamed + "_highlighted"), forState: UIControlState.Highlighted)
        button.sizeToFit()
        self.init(customView:button)
    }
    
    
}